package com.yingside.clazz.string;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

public class Test {
    public static void main(String[] args) {
//        String str = "abc";
//        str = str + "d" + "e";
//        System.out.println("str = " + str);
//
//        StringBuffer sb = new StringBuffer();
//        sb.append("a").append("b").append("c");
//        System.out.println("StringBuffer==" + sb.toString());
//
//        //StringBuilder用法一模一样
//
//        StringBuilder sbl = new StringBuilder();
//        sbl.append("a").append("b").append("c");
//        System.out.println("StringBuilder==" + sbl.toString());

        /*long start = System.currentTimeMillis();
        String str = "";
        for (int i = 0; i < 5000 ; i++) {
            str += "a" + i;
        }
        long end = System.currentTimeMillis();

        long diff = end - start;
        System.out.println("diff = " + diff);*/

        /*long start = System.currentTimeMillis();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < 5000 ; i++) {
            sb.append("a").append(i);
        }
        long end = System.currentTimeMillis();

        long diff = end - start;
        System.out.println("diff = " + diff);*/

        /*long start = System.currentTimeMillis();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 5000 ; i++) {
            sb.append("a").append(i);
        }
        long end = System.currentTimeMillis();

        long diff = end - start;
        System.out.println("diff = " + diff);*/

//        String str = "abcd";
//        char c = str.charAt(-1);
//        System.out.println("c = " + c);

//        String str1 = "abcde";
//        String str2 = "abhde";
//        System.out.println(str1.compareTo(str2));

        /*String str1 = "abc";
        String str2 = "ABC";

        System.out.println(str1.equalsIgnoreCase(str2));*/


        String str = "abc";
//        String def = str.concat("def");
//        System.out.println(def);

//        boolean c = str.contains("c");
//        System.out.println("c = " + c);


//        String s = String.copyValueOf(new char[]{'a', 'b', 'c'},1,2);
//        System.out.println(s);

        /*String [] files = {"xxx.avi","java学习.jpg","java面向对象.gif","TestJFram.java","Test2.java"};
        for (int i = 0; i < files.length; i++) {
            if(files[i].endsWith(".java")){
                System.out.println("files[i] = " + files[i]);
            }
        }*/

        // 以后用经常用来转换字符编码
        /*try {
            byte [] bs = "asdsadas".getBytes("utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }*/

        /*String str2 = "我要祖国,我爱祖国的美好河山,我要祖国可爱的人";

        int index = str2.indexOf("祖国");

        System.out.println(str2.indexOf("祖国",str2.indexOf("祖国") + "祖国".length()));


        System.out.println(str2.lastIndexOf("祖国"));


        String replace = str2.replace("祖国", "四川");
        System.out.println(replace);

        String[] split = str2.split(",");

        System.out.println("Arrays.toString(split) = " + Arrays.toString(split));*/

        /*String str3 = "abcdefghijk";

        //一个参数就表示从哪里开始，截取到最后
        String substring = str3.substring(1);
        System.out.println("substring = " + substring);

        //两个参数表示从哪里开始，截取到哪里结束
        //注意结束位置应该是end-1,
        // 简单来说 截取包括开始的位置，但是不包括结束的位置
        String substring1 = str3.substring(1, 4);
        System.out.println("substring1 = " + substring1);*/


//        String str4 = " ja ck  ";
//        System.out.println("====" + str4 + "====") ;
//        System.out.println("====" + str4.trim() + "====");
//
//        String str5 = "my name is zhangSan, my sex is male";
//        String[] s = str5.split(" ");
//        for (int i = 0; i < s.length; i++) {
//            if(s[i].length() > 1){
//                s[i] = s[i].substring(0,1).toUpperCase() + s[i].substring(1);
//            }
//            else{
//                s[i] = s[i].toUpperCase();
//            }
//        }
//
//        System.out.println(Arrays.toString(s));


        String str1 = "aaa";
        String str2 = "aaa";
        String str3 = new String("aaa");
        String str4 = new String("aaa");

        System.out.println(str1 == str2);
        System.out.println(str3 == str4);









    }
}
